package com.powergisol.gis.service.impl;

import com.powergisol.gis.dao.DynamicColumnMapper;
import com.powergisol.gis.dto.DynamicColumnDTO;
import com.powergisol.gis.entity.DynamicColumn;
import com.powergisol.gis.service.DynamicColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DynamicColumnServiceImpl implements DynamicColumnService {

    @Autowired
    DynamicColumnMapper dynamicColumnMapper;
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = {Exception.class})
    @Override
    public DynamicColumnDTO getDynamicColumn(Integer isUpdate) {

        DynamicColumnDTO dynamicColumnDTO = new DynamicColumnDTO();
        List<DynamicColumn> zk = null;
        if(isUpdate == 0){
             zk = dynamicColumnMapper.selectByPrimaryKeyTwo("1");
        }else{
             zk = dynamicColumnMapper.selectByPrimaryKey("1");
        }
        List<DynamicColumn>  tc = dynamicColumnMapper.selectByPrimaryKey("2");
        List<DynamicColumn>  sw = dynamicColumnMapper.selectByPrimaryKey("3");
        Map<String,List<DynamicColumn> > data = new HashMap<>();
        data.put("zuankong",zk);
        data.put("tabZkTucengs",tc);
        data.put("tabZkShuiweis",sw);
        dynamicColumnDTO.setResultData(data);

        return dynamicColumnDTO;
    }

    @Override
    public List<String> getSWClass() {

        return dynamicColumnMapper.getSWClass();
    }
}
